#include <pthread.h>
#include <iostream>
#include <unistd.h>
#include <time.h>
#include "blockqueue.hpp"
void* Consumer(void* args){
    BlockQueue<int>* bq = static_cast<BlockQueue<int>*>(args);
    while(true){
    //1.拿数据
    int data;
    bq->Pop(&data);
    //2.处理数据
    std::cout << "Consumer: " << data << std::endl;
    }
}
void* Productor(void* args){
    srand(time(nullptr));
    BlockQueue<int>* bq = static_cast< BlockQueue<int>*>(args);
    while(true){
       sleep(2);
       //1.构建数据
       int data = rand();
       //2.生产数据
       bq->Equeue(data);
       std::cout << "Productor: " << data << std::endl;
    }
}
int main()
{  
    BlockQueue<int>* bq = new  BlockQueue<int>();
    pthread_t c;
    pthread_t p;
    pthread_create(&c, nullptr, Consumer, bq);    

    pthread_create(&p, nullptr, Productor, bq);

    pthread_join(c, nullptr);
    pthread_join(p, nullptr);
    return 0;
}